// created by noellynch
// Jun 4, 2009

package com.sceneworker.editors.glslshadereditor.uniformreps;

import java.util.ArrayList;

import javax.swing.JPanel;
import javax.swing.JTextField;

import com.jme.scene.state.GLSLShaderObjectsState;
import com.jme.util.shader.ShaderVariable;
import com.jme.util.shader.uniformtypes.ShaderVariableMatrix2;
import com.myjavautils.swing.MigLayoutUtils;
import com.sceneworker.editors.glslshadereditor.UniformRepresentations.IUniformRepresentation;

public class Mat2Rep extends BaseUniformRep implements IUniformRepresentation {

	public static final String NAME = "Mat2x2";

	public Mat2Rep() {
	}

	@Override
	public String getNameRep() {
		return NAME;
	}

	public void createUniform(GLSLShaderObjectsState cl_state, String str_name) {
		cl_state.setUniform(str_name, new float[] { 0.0f, 0.0f, 0.0f, 0.0f }, true);
	}

	public Class<?> getUniformClassRep() {
		return ShaderVariableMatrix2.class;
	}

	public ArrayList<JTextField> getUIRep(ShaderVariable cl_v, JPanel cl_parentPanel) {
		ShaderVariableMatrix2		lcl_v = (ShaderVariableMatrix2)cl_v;
		
		lcl_v.matrixBuffer.rewind();
		JTextField		lcl_v1 = MigLayoutUtils.numberText(cl_parentPanel, "00", lcl_v.matrixBuffer.get(), false);
		JTextField		lcl_v2 = MigLayoutUtils.numberText(cl_parentPanel, "01", lcl_v.matrixBuffer.get(), true);
		JTextField		lcl_v3 = MigLayoutUtils.numberText(cl_parentPanel, "10", lcl_v.matrixBuffer.get(), false);
		JTextField		lcl_v4 = MigLayoutUtils.numberText(cl_parentPanel, "11", lcl_v.matrixBuffer.get(), true);
		
		return uiFields(lcl_v1, lcl_v2, lcl_v3, lcl_v4);
	}

	public String getValueRep(ShaderVariable cl_v) {
		ShaderVariableMatrix2	lcl_v = (ShaderVariableMatrix2)cl_v;
		lcl_v.matrixBuffer.rewind();
		return out("00 : " + lcl_v.matrixBuffer.get(), 
				"01 : " + lcl_v.matrixBuffer.get() + "\n", 
				"10 : " + lcl_v.matrixBuffer.get(), 
				"01 : " + lcl_v.matrixBuffer.get() + "\n", 
				"row major : " + lcl_v.rowMajor);
	}
	
	public	void	updateFromUI(GLSLShaderObjectsState cl_shaderState, ArrayList<JTextField> cla_values, ShaderVariable cl_v) {
		float	lfa_v[] = new float[4];
		lfa_v[0] = Float.parseFloat(cla_values.get(0).getText());
		lfa_v[1] = Float.parseFloat(cla_values.get(1).getText());
		lfa_v[2] = Float.parseFloat(cla_values.get(2).getText());
		lfa_v[3] = Float.parseFloat(cla_values.get(3).getText());
		cl_shaderState.setUniform(cl_v.name, lfa_v, true);
	}

}
